package com.example.ojsystem.controller.exam;

import com.example.ojcommencore.core.controller.BaseController;
import com.example.ojcommencore.core.domain.R;
import com.example.ojcommencore.core.domain.TableDataInfo;
import com.example.ojsystem.domain.exam.dto.ExamAddDTO;
import com.example.ojsystem.domain.exam.dto.ExamEditDTO;
import com.example.ojsystem.domain.exam.dto.ExamQueryDTO;
import com.example.ojsystem.domain.exam.dto.ExamQuestAddDTO;
import com.example.ojsystem.domain.exam.vo.ExamDetailVO;
import com.example.ojsystem.service.exam.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService iExamService;

    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO) {
        return getTableDataInfo(iExamService.list(examQueryDTO));
    }

    @PostMapping("/add")
    public R<String> add(@RequestBody ExamAddDTO examAddDTO) {
        return R.ok(iExamService.add(examAddDTO));
    }

    @PostMapping("/question/add")
    public R<Void> questionAdd(@RequestBody ExamQuestAddDTO examQuestAddDTO) {
        return toR(iExamService.questionAdd(examQuestAddDTO));
    }

    @GetMapping("/detail")
    public R<ExamDetailVO> detail(Long examId) {
        return R.ok(iExamService.detail(examId));
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return toR(iExamService.edit(examEditDTO));
    }

    // 编辑竞赛中的题目删除
    @DeleteMapping("/question/delete")
    public R<Void> questionDelete(Long examId, Long questionId) {
        return toR(iExamService.questionDelete(examId, questionId));
    }

    // 删除竞赛
    @DeleteMapping("/delete")
    public R<Void> delete(Long examId) {
        return toR(iExamService.delete(examId));
    }
}
